package com.fangsheng.rocketmq;

import org.apache.rocketmq.client.producer.MessageQueueSelector;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageQueue;

import java.util.List;

/**
 * @创建人: 放生
 * @创建时间: 2022/1/22
 * @描述: 自定义的一个选择器
 */
public class MyMessageQueueSelector implements MessageQueueSelector {


    MyMessageQueueSelector(){
        System.out.println("create selector.....");
    }


    @Override
    public MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) {

        Integer index = (Integer) arg;
        int target = index % mqs.size();
        return mqs.get(target);
    }



}
